# Do commit

require 'net/http'
require 'uri'
require 'json'

def commit(url, data)  
    url = URI.parse(url)  
    req = Net::HTTP::Post.new(url.path, {'Content-Type' => 'application/json'})  
    req.body = data  
    res = Net::HTTP.new(url.host, url.port).start{|http| http.request(req)}  

    puts res.body
end

data = <<DATA_TO_COMMIT
{
	"station": "station id",
	"token": "abcdefg",
	"entry":[
		{
		"device": "hpic",
		"time": "2013-01-02 19:05:00",
		"1020304050": "DATA VALUE"
		},
		{
		"device": "weather",
		"time": "2013-01-02 19:05:00",
		"1020304051": "DATA VALUE"
		}
	]
}
DATA_TO_COMMIT

begin
	# Test API data/commit
	#
	p JSON.parse(data)
	commit("http://127.0.0.1/data/commit", data)
rescue JSON::ParserError
	puts "Check your Json Data format."
rescue Exception => e
	puts e
end

